﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AMS.DD35.Common;
using System.ServiceModel;
using AMS.Core;
using AMS.DD35.WcfConnector.DD35Service;

namespace AMS.DD35.WcfConnector
{
    public class StaticLookupProxy : IStaticLookupService
    {
        private DD35MasterServiceClient _dd35service;

        public StaticLookupProxy()
        {
            RestartConnection();
        }

        public Dictionary<int, string> GetRaces()
        {
            try
            {
                return _dd35service.GetRaces();
            }
            catch (FaultException)
            {
                RestartConnection();
                ExceptionHandler.Exception("failed to get races");
                return null;
            }
        }

        public Dictionary<int, string> GetDeities()
        {
            try
            {
                return _dd35service.GetDeities();
            }
            catch (FaultException)
            {
                RestartConnection();
                ExceptionHandler.Exception("failed to get deities");
                return null;
            }
        }

        public Dictionary<int, string> GetFeats()
        {
            try
            {
                return _dd35service.GetFeats();
            }
            catch (FaultException)
            {
                RestartConnection();
                ExceptionHandler.Exception("failed to get Feats");
                return null;
            }
        }

        public Dictionary<int, string> GetSkills()
        {
            try
            {
                return _dd35service.GetSkills();
            }
            catch (FaultException)
            {
                RestartConnection();
                ExceptionHandler.Exception("failed to get skills");
                return null;
            }
        }

        public Dictionary<string, string> GetClasses()
        {
            try
            {
                return _dd35service.GetClasses();
            }
            catch (FaultException)
            {
                RestartConnection();
                ExceptionHandler.Exception("failed to get classes");
                return null;
            }
        }

        public Dictionary<long, string> GetCharacters(object sessionVariable)
        {
            try
            {
                return _dd35service.GetCharacters(sessionVariable);
            }
            catch (FaultException)
            {
                RestartConnection();
                ExceptionHandler.Exception("failed to get characters");
                return null;
            }
        }

        private void RestartConnection()
        {
            _dd35service = new DD35MasterServiceClient("WS2007HttpBinding_IDD35MasterService");
        }
    }
}